import { IFsm } from "./IFsm";
import ccclass = cc._decorator.ccclass;
import {Fsm} from "./Fsm";
@ccclass("FsmState")
export abstract class FsmState<T> {
    get baseName(){
        return "FsmState";
    }

    get name():string{
        return (<any>this).__proto__.constructor.name;
    }

    OnInit(fsm:IFsm<T> ):void{

    }

    OnEnter(fsm:IFsm<T>):void
    {

    }

    OnUpdate(fsm:IFsm<T>,elapseSeconds:number,realElapseSeconds:number):void
    {

    }

    OnLeave(fsm:IFsm<T>,isShutdown:boolean):void{

    }

    OnDestroy(fsm:IFsm<T>):void{

    }

    ChangeState(fsm:IFsm<T>,typeState):void{
        let fsmImplement = fsm as Fsm<T>;
        if (fsmImplement == null)
        {
            throw new Error("FSM is invalid.");
        }
        fsmImplement.ChangeState(typeState.prototype);
    }



}